package com.ruoyi.web.controller.warning;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.warning.domain.EarlyWarningSetting;
import com.ruoyi.warning.service.IEarlyWarningSettingService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预警设置Controller
 * 
 * @author ruoyi
 * @date 2024-11-24
 */
@RestController
@RequestMapping("/warning/earlyWarning")
public class EarlyWarningSettingController extends BaseController
{
    @Autowired
    private IEarlyWarningSettingService earlyWarningSettingService;


    /**
     * 查询预警设置列表
     */
    @PreAuthorize("@ss.hasPermi('warning:earlyWarning:list')")
    @GetMapping("/list")
    public TableDataInfo list(EarlyWarningSetting earlyWarningSetting)
    {
        startPage();
        List<EarlyWarningSetting> list = earlyWarningSettingService.selectEarlyWarningSettingList(earlyWarningSetting);
        return getDataTable(list);
    }

    /**
     * 导出预警设置列表
     */
    @PreAuthorize("@ss.hasPermi('warning:earlyWarning:export')")
    @Log(title = "预警设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EarlyWarningSetting earlyWarningSetting)
    {
        List<EarlyWarningSetting> list = earlyWarningSettingService.selectEarlyWarningSettingList(earlyWarningSetting);
        ExcelUtil<EarlyWarningSetting> util = new ExcelUtil<EarlyWarningSetting>(EarlyWarningSetting.class);
        util.exportExcel(response, list, "预警设置数据");
    }

    /**
     * 获取预警设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('warning:earlyWarning:query')")
    @GetMapping(value = "/{earlyWarningId}")
    public AjaxResult getInfo(@PathVariable("earlyWarningId") String earlyWarningId)
    {
        return success(earlyWarningSettingService.selectEarlyWarningSettingByEarlyWarningId(earlyWarningId));
    }

    /**
     * 新增预警设置
     */
    @PreAuthorize("@ss.hasPermi('warning:earlyWarning:add')")
    @Log(title = "预警设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EarlyWarningSetting earlyWarningSetting)
    {
        return toAjax(earlyWarningSettingService.insertEarlyWarningSetting(earlyWarningSetting));
    }

    /**
     * 修改预警设置
     */
    @PreAuthorize("@ss.hasPermi('warning:earlyWarning:edit')")
    @Log(title = "预警设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EarlyWarningSetting earlyWarningSetting)
    {
        return toAjax(earlyWarningSettingService.updateEarlyWarningSetting(earlyWarningSetting));
    }

    /**
     * 删除预警设置
     */
    @PreAuthorize("@ss.hasPermi('warning:earlyWarning:remove')")
    @Log(title = "预警设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{earlyWarningIds}")
    public AjaxResult remove(@PathVariable String[] earlyWarningIds)
    {
        return toAjax(earlyWarningSettingService.deleteEarlyWarningSettingByEarlyWarningIds(earlyWarningIds));
    }
}
